package com.nodusk.result;

import java.util.List;
import java.util.Map;

public class Pager<T> {
  private long totalRecords;
  
  private long totalPages;
  
  private int pageSize;
  
  private long curPage;
  
  private boolean firstPage = false;
  
  private boolean lastPage = false;
  
  private long startPage;
  
  private long endPage;
  
  private long startIndex;
  
  private long endIndex;
  
  private Map<String, Object> condition;
  
  private Integer code;
  
  private String msg;
  
  private Object totalRow;
  
  private List<T> datas;
  
  private Map<String, Object> map;
  
  public Object getTotalRow() {
    return this.totalRow;
  }
  
  public void setTotalRow(Object totalRow) {
    this.totalRow = totalRow;
  }
  
  public Map<String, Object> getMap() {
    return this.map;
  }
  
  public void setMap(Map<String, Object> map) {
    this.map = map;
  }
  
  public Pager(long totalRecords, Integer pageSize, Long curPage) {
    this.totalRecords = totalRecords;
    if (pageSize == null || pageSize.intValue() < 1) {
      this.pageSize = 10;
    } else {
      this.pageSize = pageSize.intValue();
    } 
    this
      .totalPages = (this.totalRecords % this.pageSize == 0L) ? (this.totalRecords / this.pageSize) : (this.totalRecords / this.pageSize + 1L);
    if (curPage == null || curPage.longValue() < 1L) {
      this.curPage = 1L;
    } else {
      this.curPage = curPage.longValue();
    } 
    if (this.curPage > this.totalPages)
      this.curPage = this.totalPages; 
    this.startIndex = (this.curPage - 1L) * this.pageSize;
    this.endIndex = this.startIndex + this.pageSize;
    if (this.curPage == 1L)
      this.firstPage = true; 
    if (this.curPage == this.totalPages)
      this.lastPage = true; 
    if (this.totalPages <= 10L) {
      this.startPage = 1L;
      this.endPage = this.totalPages;
    } else if (this.curPage <= 6L) {
      this.startPage = 1L;
      this.endPage = 10L;
    } else {
      this.startPage = this.curPage - 5L;
      this.endPage = this.curPage + 4L;
      if (this.endPage > this.totalPages)
        this.endPage = this.totalPages; 
    } 
  }
  
  public long getTotalRecords() {
    return this.totalRecords;
  }
  
  public long getTotalPages() {
    return this.totalPages;
  }
  
  public int getPageSize() {
    return this.pageSize;
  }
  
  public long getCurPage() {
    return this.curPage;
  }
  
  public boolean isFirstPage() {
    return this.firstPage;
  }
  
  public boolean isLastPage() {
    return this.lastPage;
  }
  
  public long getStartPage() {
    return this.startPage;
  }
  
  public long getEndPage() {
    return this.endPage;
  }
  
  public long getStartIndex() {
    return this.startIndex;
  }
  
  public long getEndIndex() {
    return this.endIndex;
  }
  
  public Map<String, Object> getCondition() {
    return this.condition;
  }
  
  public List<T> getDatas() {
    return this.datas;
  }
  
  public void setCondition(Map<String, Object> condition) {
    this.condition = condition;
  }
  
  public void setDatas(List<T> datas) {
    this.datas = datas;
  }
  
  public Integer getCode() {
    return this.code;
  }
  
  public void setCode(Integer code) {
    this.code = code;
  }
  
  public String getMsg() {
    return this.msg;
  }
  
  public void setMsg(String msg) {
    this.msg = msg;
  }
}
